package com.sas.hnn;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;

public class HeaderRow extends Fragment implements OnClickListener {

	private String TAG = HeaderRow.class.getSimpleName();

	private Button b_name;
	private Button b_age;
	private Button b_street;
	private Button b_locale;
	private View mContentView;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContentView = inflater.inflate(R.layout.header_row, null);

		initialisiere();
		return mContentView;
	}

	private void initialisiere() {
		b_name = (Button) mContentView.findViewById(R.id.b_name);
		b_age = (Button) mContentView.findViewById(R.id.b_age);
		b_street = (Button) mContentView.findViewById(R.id.b_street);
		b_locale = (Button) mContentView.findViewById(R.id.b_locale);

		b_name.setOnClickListener(this);
		b_age.setOnClickListener(this);
		b_street.setOnClickListener(this);
		b_locale.setOnClickListener(this);
	}

	/*
	 * Das tippen auf die Spaltenbeschriftung sortiert die Liste.
	 */
	public void onClick(View v) {
		PersonList frag = (PersonList) getFragmentManager().findFragmentById(
				R.id.frag_rows);
		switch (v.getId()) {
		case R.id.b_name:
			Persons.sortWhat = "name";
			break;
		case R.id.b_age:
			Persons.sortWhat = "age";
			break;
		case R.id.b_street:
			Persons.sortWhat = "street";
			break;
		case R.id.b_locale:
			Persons.sortWhat = "locale";
			break;
		default:
			Persons.sortWhat = "none";
			break;
		}
		frag.sort();

	}

}
